#include "foohelper.h"
#include "policykithelper.h"
#include <QCoreApplication>
#include <QDBusConnection>
#include <QDebug>
#include <QProcess>
#include <polkit-qt5-1/PolkitQt1/Authority>


using namespace std;
using namespace PolkitQt1;

FooHelper::FooHelper(QObject *parent)
{

}


FooHelper::~FooHelper()
{

}

void FooHelper::installdeb(QString debname)
{
    if(PolicyKitHelper::instance()->checkAuthorization("com.redflag.debinstall", getpid())){
        qDebug()<< "开始安装";
        QProcess *cmd;
        cmd = new QProcess();
        QString str_cmd = QString("apt install ");
        qDebug() << "str_cmd = " << str_cmd + debname;
        cmd->start("bash",QStringList() <<"-c" << str_cmd + debname);
        cmd->waitForFinished();
        QString strResult = cmd->readAllStandardOutput().data();
        qDebug()<< strResult;
        if(cmd)
        {
                cmd->close();
        }
        //system("apt install htop");
    }
}

